package game;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;

public class Tank {
	private Point2D.Double position;
	private int angle;
	private BufferedImage body;
	private boolean moveRight, moveLeft, moveForward, moveReverse;
	private int SPEED = 2;
	
	public Tank(double x, double y, int angle){
		moveRight = moveLeft = moveForward = moveReverse = false;
		position = new Point2D.Double(x, y);
		this.angle = angle;
		body = loadImage();
	}
	
	public void move(){
		if(moveForward)
			position.setLocation(position.x + SPEED, position.y);
		else if(moveReverse)
			position.setLocation(position.x - SPEED, position.y);
	}
	
	private BufferedImage loadImage(){
		try{
			BufferedImage im = ImageIO.read(getClass().getResource("/pictures/tankBody.png"));
			return im;
		}
		catch(IOException e){e.printStackTrace(); return null;}
	}
	
	public void draw(Graphics g){
		g.drawImage(body, (int)position.x, (int)position.y, null);
	}
	
	public void moveRight(boolean move){
		moveRight = moveLeft ? false : move;
	}
	
	public void moveLeft(boolean move){
		moveLeft = moveRight ? false : move;
	}
	
	public void moveForward(boolean move){
		moveForward = moveReverse ? false : move;
	}
	
	public void moveReverse(boolean move){
		moveReverse = moveForward ? false : move;
	}
}
